<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">



    <h:head>

    </h:head>

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">

                <h:panelGroup >
                    <h:form  >
                        <p:growl />
                        <p:panel header="Add Family" >
                            <p:panelGrid columns="2" >
                                <p:commandButton value="Save Family" action="#{patientController.saveFamily()}" ></p:commandButton>
                                <p:commandButton value="Save &amp; Clear for a new Family" action="#{patientController.saveAndClearForNewFamily() }" ></p:commandButton>
                            </p:panelGrid>

                            <p:panelGrid columns="2" styleClass="alignTop" >
                                <p:panel header="Family Membership" >
                                    <p:panelGrid columns="2">
                                        <p:outputLabel value="Membership Card No:" for="membershipCardNo" />
                                        <p:inputText
                                            autocomplete="off" id="membershipCardNo" value="#{patientController.currentFamily.membershipCardNo}" title="MembershipCardNo" />

                                        <p:outputLabel value="Phone No.:" for="phoneNo" />
                                        <p:inputText  autocomplete="off"
                                                      id="phoneNo" value="#{patientController.currentFamily.phoneNo}" title="MembershipCardNo" />


                                        <p:outputLabel value="MembershipScheme:" for="membershipScheme" />
                                        <p:selectOneMenu id="membershipScheme" value="#{patientController.currentFamily.membershipScheme}" >
                                            <f:selectItems value="#{membershipSchemeController.items}" var="m" itemLabel="#{m.name}" itemValue="#{m}"/>
                                        </p:selectOneMenu>
                                        <p:outputLabel value="Comments:" for="comments" />
                                        <p:inputTextarea rows="4" cols="30" id="comments" value="#{patientController.currentFamily.comments}" title="Comments" />
                                    </p:panelGrid>
                                </p:panel>
                                <p:panel header="Add Family Members" >
                                    <p:panelGrid columns="2">

                                        <h:outputLabel value="Search by Name/Code/Phone/NIC/PHN" />
                                        <p:autoComplete widgetVar="aPt" id="acPt" forceSelection="true" 
                                                        value="#{patientController.current}" minQueryLength="4"
                                                        completeMethod="#{patientController.completePatientByNameOrCode}" 
                                                        var="apt" itemLabel="#{apt.person.name}" 
                                                        itemValue="#{apt}" size="30"  style="width: 400px;"
                                                        >
                                            <p:column headerText="Name">
                                                <h:outputLabel value="#{apt.person.nameWithTitle}" />
                                            </p:column>

                                            <p:column headerText="Age">
                                                <h:outputLabel value="#{apt.age}" />
                                            </p:column>
                                            <p:column headerText="NIC">
                                                <h:outputLabel value="#{apt.person.nic}"/>
                                            </p:column>
                                            <p:column headerText="Code">
                                                <h:outputLabel value="#{apt.code}" />
                                            </p:column>
                                            <p:column headerText="PHN">
                                                <h:outputLabel value="#{apt.phn}"/>
                                            </p:column>
                                            <p:column headerText="Sex">
                                                <h:outputLabel value="#{apt.person.sex}" />
                                            </p:column>
                                            <p:column headerText="Address">
                                                <h:outputLabel value="#{apt.person.address}" />
                                            </p:column>
                                            <p:column headerText="Date of Birth">
                                                <h:outputLabel value="#{apt.person.dob}" >
                                                    <f:convertDateTime pattern="dd MMMM yyyy"/>
                                                </h:outputLabel>
                                            </p:column>
                                        </p:autoComplete>

                                        <p:outputLabel value="Relationship to Chief House Holder" />
                                        <p:selectOneMenu value="#{patientController.currentRelation}" >
                                            <f:selectItems value="#{relationController.items}" var="r"
                                                           itemLabel="#{r.name}" itemValue="#{r}" ></f:selectItems>
                                        </p:selectOneMenu>


                                        <p:spacer></p:spacer>
                                        <p:commandButton ajax="false" value="Add as a Family Member"
                                                         action="#{patientController.addNewMemberToFamily()}">
                                        </p:commandButton>

                                        <p:spacer></p:spacer>
                                        <p:commandButton ajax="false" value="To add a new Family Member" 
                                                         action="#{patientController.toNewPatient()}" >

                                        </p:commandButton>

                                    </p:panelGrid>

                                </p:panel>
                            </p:panelGrid>
                            <p:panel header="Family Members" >
                                <p:dataTable value="#{patientController.currentFamily.familyMembers}" var="fm"
                                             rowIndexVar="#{fm.id}"
                                             style="table-layout: auto;">
                                    <p:column headerText="Name">
                                        <p:outputLabel value="#{fm.patient.person.nameWithTitle}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Relation to CHH">
                                        <p:outputLabel value="#{fm.relationToChh.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Membership" rendered="false">
                                        <p:outputLabel value="#{fm.patient.person.membershipScheme.name}" ></p:outputLabel>
                                    </p:column>
                                    <p:column headerText="Billing">

                                        <p:commandButton ajax="false" action="/opd_bill"  actionListener="#{billController.prepareNewBillForMember()}" 
                                                         value="OPD" disabled="#{!webUserController.hasPrivilege('OpdBilling')}" >
                                            <f:setPropertyActionListener value="#{fm.patient}" target="#{billController.searchedPatient}" ></f:setPropertyActionListener>
                                        </p:commandButton>
                                        <p:commandButton ajax="false" action="/channel/channel_booking" 
                                                         actionListener="#{channelBillController.prepareForNewChannellingBillForMember()}" 
                                                         value="Channelling" disabled="#{!webUserController.hasPrivilege('ChannellingChannelBooking')}" >
                                            <f:setPropertyActionListener value="#{fm.patient}" target="#{channelBillController.searchPatient}" ></f:setPropertyActionListener>
                                        </p:commandButton>
                                        <p:commandButton ajax="false" action="/pharmacy/pharmacy_bill_retail_sale" 
                                                         actionListener="#{pharmacySaleController.prepareNewPharmacyBillForMembers()}" 
                                                         value="Phamacy" disabled="#{!webUserController.hasPrivilege('ChannellingChannelBooking')}" >
                                            <f:setPropertyActionListener value="#{fm.patient}" target="#{pharmacySaleController.searchedPatient}" ></f:setPropertyActionListener>
                                        </p:commandButton>
                                        <p:commandButton ajax="false" action="#{admissionController.toAdmitAMember()}" 
                                                         value="Admit" disabled="#{!webUserController.hasPrivilege('InwardAdmissionsAdmission')}" >
                                            <f:setPropertyActionListener value="#{fm.patient}" target="#{admissionController.current.patient}" ></f:setPropertyActionListener>
                                        </p:commandButton>

                                    </p:column>
                                    <p:column headerText="Actions" >
                                        <p:commandButton ajax="false" value="Edit" action="patient" >
                                            <f:setPropertyActionListener value="#{fm.patient}" target="#{patientController.current}" ></f:setPropertyActionListener>
                                        </p:commandButton>
                                        <p:commandButton ajax="false" value="Remove" action="#{patientController.removeFamilyMember()}" >
                                            <f:setPropertyActionListener value="#{fm}" target="#{patientController.removingFamilyMember}" ></f:setPropertyActionListener>
                                        </p:commandButton>
                                    </p:column>
                                </p:dataTable>
                            </p:panel>




                        </p:panel>
                    </h:form>
                </h:panelGroup>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
